package shading;

import java.awt.Color;

import raytracing.RaycastResult;
import structs.Vector3;

public class LambertianShader implements IShader {

	@Override
	public Color getShading(RaycastResult result, Vector3 dirToLight, Color lightColor) {
		if(result.normal == null)
			return result.diffuseColor;
		
		float theta = 0;
		float temp = result.normal.dotproduct(dirToLight);
		if (temp > 0)
			theta = temp;

		float r = (float)result.diffuseColor.getRed() / 255 * lightColor.getRed() / 255 * theta;
		float g = (float)result.diffuseColor.getGreen() / 255 * lightColor.getGreen() / 255 * theta;
		float b = (float)result.diffuseColor.getBlue() / 255 * lightColor.getBlue() / 255 * theta;
		Color c = new Color(r, g, b);
		return c;
	}

}
